package leetcode100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class lc020 {

    public static void main(String[] args) {
        int[] nums = new int[]{1,1};
        List<Integer> list = findDisappearedNumbers(nums);
        System.out.println("list = " + list);

    }

    public static List<Integer> findDisappearedNumbers(int[] nums) {
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            System.out.println(Arrays.toString(nums));
            index = Math.abs(nums[i]) - 1;
            if (nums[index] > 0)
                nums[index] = -nums[index];
        }

        /**
         *
         * 直接使用流会失去索引信息
         *
         */

//        int [] res = Arrays.stream(nums).filter(v->v>0).toArray();


        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] >0) {
                res.add(i + 1);
            }
        }

        return res;

    }
}
